package com.fanfanwang.ffw.app.db;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;


public class BaseDBUtil {


	public static Uri build(String path, String id) {
		final Uri.Builder builder = new Uri.Builder();
		builder.scheme(ItotemContract.SCHEME);
		builder.authority(ItotemContract.AUTHORITY);
		builder.path(path);
		builder.appendPath(id);
		return builder.build();

	}

	public static Uri build(String path) {
		final Uri.Builder builder = new Uri.Builder();
		builder.scheme(ItotemContract.SCHEME);
		builder.authority(ItotemContract.AUTHORITY);
		builder.path(path);
		return builder.build();
	}

	public static String urlDecode(String url) {
		String decodeUrl = null;
		try {
			decodeUrl = URLEncoder.encode(url, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			decodeUrl = url;
			e.printStackTrace();
		}
		return decodeUrl;
	}

	/**
	 * 将图片转化为二进制的方法
	 * 
	 * @param bitMap
	 *            要转换的图片
	 * @return byte数组的字符串表示
	 */
	public static byte[] changeBitmapToByte(Bitmap bitMap) {
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		bitMap.compress(Bitmap.CompressFormat.PNG, 100, bos);
		return bos.toByteArray();
	}

	/**
	 * 将二进制转化为图片的方法
	 * 
	 * @param b
	 * @return
	 */
	public static Bitmap changeByteToBitmap(byte[] b) {
		Bitmap bitmap = null;
		if (b.length != 0) {
			bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
		}
		return bitmap;
	}

}
